﻿/**
 *	\file		lxpref_route_end.hxx
 *	\date		(2014-12-19 11:28:27)/(2014-12-19 11:28:27)
 *-----------------------------------------------------------------------------
 *	\brief
 *	\version	1.0.0.1
 *	\author		Nick Shallery	(nicknide@gmail.com)
 *	\copyright	YOU HAVE ALL LEFT WITH THIS CODE WHILE YOU KEEP COMMENT IN EVERY COPY.
 *-----------------------------------------------------------------------------
**/

#if			!defined(__LOLIX__PROFILE__LX_PREF__H__NICK__K_IN_G__)
#	include	"./lxpref.h"
#endif	//	!defined(__LOLIX__PROFILE__LX_PREF__H__NICK__K_IN_G__)

#if			!defined(__LOLIX__TOY__FIFO_QUEUE__HPP__NICK__K_IN_G__)
#	include	<lolix/toy/fifo_queue.hpp>
#endif	//	!defined(__LOLIX__TOY__FIFO_QUEUE__HPP__NICK__K_IN_G__)

#if			!defined(__LOLIX__TOY__STD_MAP__NICK__K_IN_G__)
#	include	<lolix/toy/std_map.hpp>
#endif 	//	!defined(__LOLIX__TOY__STD_MAP__NICK__K_IN_G__)

#if			!defined(__LOLIX__TOY__STD_STRING__NICK__K_IN_G__)
#	include	<lolix/toy/std_string.hpp>
#endif	//	!defined(__LOLIX__TOY__STD_STRING__NICK__K_IN_G__)

namespace lolix{namespace toy{class stdc_fun;}}
namespace lolix{namespace loli{class critical_section;class critical_section_factory;}}
namespace lxsamsara{class recurrence;}
namespace lxut{namespace ctrl{class ctrl_string;class ctrl_string_factory;}}
namespace lxnet{class net_factory;class net_connect;}
namespace lxpref{namespace message{enum PREF_MSG_TYPE LOLIX_ETYPE(lolix::lx_u32);}}


namespace lxpref{namespace _inst{
	class clt_usr;
	class lxpref_route_end_inst
		: public lolix::itf_Tbase<lxpref_route_end_inst, lxpref_route_end>
	{
		LOLIX_DEFINE_ITF(lxpref::_inst::lxpref_route_end_inst, lxpref::lxpref_route_end, (0xaa66bba0, 0x5c054766, 0x9993c80d, 0x09b2d3aa));
		lolix::dynamic_allocator* _alc;
		lolix::loli::signal*	_signal;
		lxnet::net_factory*		_net_fac;
		lxnet::net_connect*		_net_conn;
		lolix::toy::stdc_fun*	_stdc;
		lxut::ctrl::ctrl_string*_str_fmt;
		event_info*				_evt_inf;
		lolix::loli::critical_section* _cs;
		lxsamsara::recurrence*	_recur;

		typedef lolix::toy::fifo_queue<event_info, lolix::THREAD_SAFE_SRMW, allocator_type> _TDatType;
		typedef lolix::toy::basic_string<lolix::lx_wchar, void, allocator_type> _TWstring;
		typedef lolix::toy::map<ptrdiff_type, _TWstring, lolix::toy::less, allocator_type> _TNameMap;
		_TDatType	_dat;
		_TNameMap	_name_map;

		lxpref_route_end_inst(lolix::loli::signal* sign, lolix::dynamic_allocator* alc);
		~lxpref_route_end_inst(void);
	public:
		static LOLIX_RETNV create_inst(this_type** out_ptr, lolix::dynamic_allocator* alc
			, lolix::ref_factory* ref_fac
			, lxnet::net_factory* net_fac
			, lolix::toy::stdc_fun* stdc
			, lxsamsara::recurrence* recur
			, lolix::loli::signal::factory_type* sig_fac
			, lolix::loli::critical_section_factory* cs_fac
			, lxut::ctrl::ctrl_string_factory* ctrl_str_fac
			, lolix::lx_wchar const* path
			, lolix::size_type path_len
			, lxio::file_async_pool* async_pool
			);
		LOLIX_INTERFACE_DEF(close	, LOLIX_RETNV, (void));
		LOLIX_INTERFACE_DEF(wait	, LOLIX_RETNV, (lolix::toy::time_span const* ts)const);
		LOLIX_INTERFACE_DEF(top		, LOLIX_RETNV, (event_info const** evt_inf));
		LOLIX_INTERFACE_DEF(fetch	, LOLIX_RETNV, (event_info const* evt_inf));
	private:
		LOLIX_RETNV _Link(lolix::lx_wchar const* path, lolix::size_type path_len, lxio::file_async_pool* async_pool);
		LOLIX_RETNV _Unlink(void);
		void LOLIX_CALL _On_read(lolix::loli::file_async_result* fas);
		static void LOLIX_CALL _On_recvPack_s(clt_usr* cusr, message::PREF_MSG_TYPE msgType, void const* buf, lolix::size_type buf_size, void* usr_ptr);
		void _On_recvPack(clt_usr* cusr, message::PREF_MSG_TYPE msgType, void const* buf, lolix::size_type buf_size);
	};
}}
